// packageA/pages/complaintDetail/complaintDetail.js
import CommonService from '../../../utils/service/commonService.js';
const util = require('../../../utils/util');
import Base64 from '../../../utils/Base64.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //传参
    paramObj:null,     
    //信息回显
    editInfo:{}  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { 
    if(options.paramObj){
      let paramObj=JSON.parse(options.paramObj);
      console.log('投诉工单详情传参');
      console.log(paramObj);

      this.setData({
        paramObj: paramObj
      })

      if(paramObj.id){
        //获取修改的数据
        this.getInfo();
      }
    }
  },

  //获取修改的数据
  getInfo(){
    let param = {
      isAuth: false,
      className: 'complaintOrder',
      data: {
        id:this.data.paramObj.id,
				selectFields: ['id','project','place','problem','name','createUser','phone','createDate','pic','type','handler','planCompletionTime','dispatchTime','handleTime','handleResult','handlePic','evaluateScore','evaluateContent','checkTime','state'],
				nbl: Base64.encode(util.timeFormatDay(new Date()))
      }
    }

    CommonService.goFindList(param).then(res => {
      if(res.data.data && res.data.data.result && res.data.data.result.length) {
				let result=res.data.data.result[0];

        //状态
				switch(result.state){
					case 0:
						result.self_state='待派单';
						result.self_stateClass='c-0';
						break;
					case 1:
						result.self_state='已完成';
						result.self_stateClass='c-1';
						break;
					case 2:
						result.self_state='待处理';
						result.self_stateClass='c-2';
						break;
					case 3:
						result.self_state='待验收';
						result.self_stateClass='c-3';
						break;
				}

        //投诉时间（创建时间）
        if(result.createDate){
          result.self_createDate = util.timeFormat(result.createDate);
				}

				//预计完成时间
				if(result.planCompletionTime){
          result.self_planCompletionTime = util.timeFormat(result.planCompletionTime);
				}

				//派单时间
				if(result.dispatchTime){
          result.self_dispatchTime = util.timeFormat(result.dispatchTime);
				}

				//处理时间
        if(result.handleTime){
          result.self_handleTime=util.timeFormat(result.handleTime);
				}
				
				//验收时间
        if(result.checkTime){
          result.self_checkTime=util.timeFormat(result.checkTime);
        }
				
        console.log('投诉工单详情');
        console.log(result);
       
        this.setData({
          editInfo: result
        })
      }
    }).catch((error) => {
    })
  },

  //预览图片
  onPreviewImage(e) {
    let detail = e.target.dataset.detail;
    let src = e.target.dataset.src;

    wx.previewImage({
      current: src,
      urls: detail
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})